package com.zbbt.sportslottery.ui.fragment;

import com.zbbt.sportslottery.R;
import com.zbbt.sportslottery.ui.activity.MainActivity;

import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.TextView;

/**
 * 
 * @ClassName: SimpleBaseFragment
 * @Description: 简单的Fragment基类
 * @author：LiZhimin
 * @备注：
 * @version V1.0
 */
public abstract class SimpleBaseFragment extends BaseFragment implements OnClickListener {
	protected View mView;
	private long clickTime = 0;
	private Toolbar toolbar;
	protected TextView tv_right;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		super.onCreateView(inflater, container, savedInstanceState);
		if (mView == null) {
			initView(inflater);
		}
		ViewGroup parent = (ViewGroup) mView.getParent();
		if (parent != null) {
			parent.removeView(mView);
		}
		initToolBar();
		setListener();
		initData();
		return mView;
	}

	/**
	 * 
	 * @MethodName:initView
	 * @Description: 加载布局 以及 findviewById
	 * @author：LiZhimin
	 * @date：2014-4-2 下午8:24:08
	 * @param inflater
	 *            void
	 */
	protected abstract void initView(LayoutInflater inflater);

	/**
	 * 
	 * @MethodName:setListener
	 * @Description: 设置监听
	 * @author：LiZhimin
	 */
	protected abstract void setListener();

	/**
	 * 
	 * @MethodName:onClickEvent
	 * @Description: 点击事件的封装
	 * @author：LiZhimin
	 * @param v
	 *            void
	 */
	protected abstract void onClickEvent(View v);

	/**
	 * 
	 * @MethodName:initData
	 * @Description: 设置数据
	 * @author：LiZhimin
	 */
	protected abstract void initData();

	@Override
	public void onClick(View v) {
		if ((System.currentTimeMillis() - clickTime) > 500) {
			clickTime = System.currentTimeMillis();
		} else {
			// LogUtil.printD(TAG, "点的太快了吧你");
			return;
		}
		onClickEvent(v);
	}

	/**
	 * 
	 * @MethodName:initToolBar
	 * @Description: 注册标题Toolbar
	 */
	protected void initToolBar() {
		toolbar = (Toolbar) findViewById(R.id.toolbar);
		if (toolbar != null) {
			toolbar.setNavigationIcon(null);
			tv_right = (TextView) findViewById(R.id.tv_right);
		}
	}

	/**
	 * 
	 * @MethodName:findViewById
	 * @Description: findViewById的抽取
	 * @author：LiZhimin
	 * @param id
	 * @return View
	 */
	protected View findViewById(int id) {
		return mView.findViewById(id);
	}

}
